﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;

public partial class QLVB_User_BaoCaoDanhSachVanBanDen : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            //Kiem tra co dang nhap khong?
            if (Session["MaNguoiDung"] == null || Session["MaNguoiDung"].ToString() == string.Empty)
            {
                Response.Redirect("~/pHome.aspx");
            }
        }

        //
        rptDanhSachVanBanDen rpt = new rptDanhSachVanBanDen();

        DataTable dt = new DataTable();
        dt.Columns.Add("SoVanBan");
        dt.Columns.Add("NoiDungVanBan");
        dt.Columns.Add("NgayHieuLuc");
        dt.Columns.Add("NgayHetHieuLuc");
        dt.Columns.Add("NgayKiemSoat");
        dt.Columns.Add("MaNoiPhatHanh");
        dt.Columns.Add("TenDonViSoanThao");
        dt.Columns.Add("NoiDungButPhe");

        VanBanBUS vbBUS = new VanBanBUS();
        DateTime ngayTu = (DateTime)Session["NgayTu_VanBanDaGui"];
        DateTime ngayDen = (DateTime)Session["NgayDen_VanBanDaGui"];
        string maHinhThuc = (String)Session["MaHinhThuc"];
        IList<VanBan> lstVanBan = vbBUS.rptDanhSachVanBanDen(ngayTu, ngayDen, maHinhThuc);
        foreach (VanBan vb in lstVanBan)
        {
            DataRow dr;
            dr = dt.NewRow();
            dr["SoVanBan"] = vb.SoVanBan;
            dr["NoiDungVanBan"] = vb.NoiDungVanBan;
            dr["NgayHieuLuc"] = vb.NgayHieuLuc;
            dr["NgayHetHieuLuc"] = vb.NgayHetHieuLuc;
            dr["NgayKiemSoat"] = vb.NgayKiemSoat;
            dr["MaNoiPhatHanh"] = vb.MaNoiPhatHanh;
            dr["TenDonViSoanThao"] = vb.TenDonViSoanThao;
            dr["NoiDungButPhe"] = vb.NoiDungButPhe;
            dt.Rows.Add(dr);
        }

        rpt.SetDataSource(dt);

        rvDanhSachVanBanDen.ReportSource = rpt;

        //Gan ngay tim kiem len TextObject
        TextObject txtNgayTu = (TextObject)rpt.ReportDefinition.Sections["Section1"].ReportObjects["txtNgayTu"];
        txtNgayTu.Text = ngayTu.ToString("dd/MM/yyyy");
        TextObject txtNgayDen = (TextObject)rpt.ReportDefinition.Sections["Section1"].ReportObjects["txtNgayDen"];
        txtNgayDen.Text = ngayDen.ToString("dd/MM/yyyy");
    }
}